package xmu.ackerman.application;

import xmu.ackerman.spring.annotation.Controller;
import xmu.ackerman.spring.annotation.RequestMapping;

import java.io.File;
import java.io.FileWriter;
import java.util.Random;

@Controller
public class Apple {

    @RequestMapping(value = "/index", method = RequestMapping.RequestMethod.GET)
    public String sayApple(){
        System.out.println("hello world");

        return "index";
    }

    @RequestMapping(value = "/test", method = RequestMapping.RequestMethod.GET)
    public String test() {
        Random random = new Random(System.currentTimeMillis());
        int filenameIndex = 1 + random.nextInt(max);

        return String.valueOf(filenameIndex);
    }

    private static int max = 10000;
    private static String prefix = "/Users/ackerman/IdeaProjects/Web-Server/HTTPServer/WEB-INF/";
    public static void main(String []args) throws Exception {
        Random random = new Random(System.currentTimeMillis());
        for (int i = 1; i <= max; ++i) {
            String filename = prefix + i + ".txt";
            File file = new File(filename);
            FileWriter fileWriter = new FileWriter(file);
            char []buf = new char[36800];
            for (int j = 0; j < buf.length; ++j) {
                buf[j] = (char) random.nextInt(102400);
            }
            fileWriter.write(buf);
            fileWriter.close();
            System.out.println("cur: " + i);
        }
    }


}
